﻿using System;
using System.Net;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //HijackShips
    public class HijackShip : StarShip
    {
        //constructor
        public HijackShip(SVGame game, Player owner, int engines, StarSystem origin)
            : base(game, owner, engines, 0, origin)
        {
        }

        //Name
        public override string Name
        {
            get
            {
                return "HijackShip";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "HijackShips capture enemy StarShips that they attack.  The HijackShip itself is destroyed after capturing a target.";
            }
        }

        //ship type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.HijackShip;
            }
        }

        //They can attack starships
        public override bool CanExecuteOrder(OrderType ot)
        {
            switch (ot)
            {
                case OrderType.TargetStarShip:
                case OrderType.Defend:
                case OrderType.DefendPoint:
                case OrderType.AttackAdjacent:
                    return true;
                default:
                    return base.CanExecuteOrder(ot);
            }
        }

        //they can attack only enemies
        public override bool CanTargetStarShip(StarShip ship, bool respectAlliance)
        {
            if (respectAlliance)
                return !Owner.FriendlyTo(ship.Owner);
            else
                return ship.Owner != Owner;
        }

        //take over the enemy - destroy self
        protected override void TargetAdjacentStarShip(StarShip target)
        {
            //change the owner and clear the order of the target
            target.Owner = Owner;
            target.Order = null;
            if (Game.Host != null)
                Game.Host.StarShipOwnerChanged(target);
            Game.SubmitStateChange(StateChange.ShipHijacked, target, Owner);

            //and destroy the hijackship
            Game.DestroyStarShip(this);
        }

        //can take out any enemy
        public override bool CanDestroy(StarShip target)
        {
            return true;
        }
    }
}
